(function($){  
	//弹窗确认工具
	$.alt = {
		//弹窗提示
		message:function(title,message,func){
			//关闭可能存在的确认框
			$("#alt-confirm").modal("hide");
			if (typeof func == "function") {
				$("#alt-message").unbind().bind("hide.bs.modal",func);
			}
			$("#alt-message").find(".modal-title").empty().text(title).end()
				.find(".modal-body").empty().text(message).end().modal('show');
		},
		//弹窗提示
		confirm:function (title,message,func,escfunc){
			if (typeof func == "function") {
				$("#alt-confirm .modal-footer button:eq(0)").unbind().bind('click',function(){
					var succ = func();
					if(succ){
						$("#alt-confirm").unbind().modal("hide");
					}
				});
			}
			if (typeof escfunc == "function") {
				$("#alt-confirm").unbind().bind("hide.bs.modal",escfunc);
			}
			$("#alt-confirm").find(".modal-title").empty().text(title).end()
				.find(".modal-body").empty().text(message).end().modal('show');
		}
	}
	
	//初始加载提示弹窗
	var initAltMessage=function(){
		//页面没有该元素时向页面填充
		if($("div[id='alt-message']").length==0){
			var messageArray=new Array();
			messageArray.push(' <div class="modal fade bs-example-modal-sm" id="alt-message" tabindex="-1" role="dialog" aria-labelledby="alt-label" aria-hidden="true" data-keyboard="false"> ');
			messageArray.push(' 	<div class="modal-dialog modal-sm"> ');
			messageArray.push(' 		<div class="modal-content"> ');
			messageArray.push(' 			<div class="modal-header"> ');
			messageArray.push(' 				<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> ');
			messageArray.push(' 				<h4 class="modal-title" id="alt-label"></h4> ');
			messageArray.push(' 			</div> ');
			messageArray.push(' 			<div class="modal-body"></div> ');
			messageArray.push(' 			<div class="modal-footer"> ');
			messageArray.push(' 				<button type="button" class="btn btn-sm btn-default" data-dismiss="modal">确定</button> ');
			messageArray.push(' 			</div> ');
			messageArray.push(' 		</div> ');
			messageArray.push(' 	</div> ');
			messageArray.push(' </div> ');
			$("body").append(messageArray.join(""));
		}
	}
	
	//初始加载提示弹窗
	var initAltConfirm=function(){
		//页面没有该元素时向页面填充
		if($("div[id='alt-confirm']").length==0){
			var confirmArray=new Array();
			confirmArray.push(' <div class="modal fade bs-example-modal-sm" id="alt-confirm" tabindex="-1" role="dialog" aria-labelledby="alt-label" aria-hidden="true" data-keyboard="false"> ');
			confirmArray.push(' 	<div class="modal-dialog modal-sm"> ');
			confirmArray.push(' 		<div class="modal-content"> ');
			confirmArray.push(' 			<div class="modal-header"> ');
			confirmArray.push(' 				<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> ');
			confirmArray.push(' 				<h4 class="modal-title" id="alt-label"></h4> ');
			confirmArray.push(' 			</div> ');
			confirmArray.push(' 			<div class="modal-body"></div> ');
			confirmArray.push(' 			<div class="modal-footer"> ');
			confirmArray.push(' 				<button type="button" class="btn btn-sm btn-primary">确定</button> ');
			confirmArray.push(' 				<button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button> ');
			confirmArray.push(' 			</div> ');
			confirmArray.push(' 		</div> ');
			confirmArray.push(' 	</div> ');
			confirmArray.push(' </div> ');
			$("body").append(confirmArray.join(""));
		}
	}
	//初始化弹窗
	initAltMessage();
	initAltConfirm();
})(jQuery);